08. Gazebo Plugins

Gazebo Plugins

You added sensors to your robot, allowing it to visualize the world around it! But how exactly does the camera sensor takes those images in simulation? How does a lidar sensor take laser measurements in simulation? How exactly does your robot move in a simulated environment?

URDF in itself can't help with that. However, Gazebo allows for plugins that implement specific use-cases.

Sensor and Actuators Plugins

We will cover the use of three such plugins:

  • A plugin for the camera sensor.
  • A plugin for the Hokuyo lidar sensor.
  • A plugin for the wheel joints actuator.

Add Plugins

Download the my_robot.gazebo file, which includes the 3 plugins mentioned above, and place it inside the urdf directory of my_robot .

Gazebo Plugin Files

Since we have a two-wheeled mobile robot, we will use a plugin that implements a differential drive controller. Let's take a look at how the plugin is defined in the my_robot.gazebo file.

  <gazebo>
    <plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
      <legacyMode>false</legacyMode>
      <alwaysOn>true</alwaysOn>
      <updateRate>10</updateRate>
      <leftJoint>left_wheel_hinge</leftJoint>
      <rightJoint>right_wheel_hinge</rightJoint>
      <wheelSeparation>0.4</wheelSeparation>
      <wheelDiameter>0.2</wheelDiameter>
      <torque>10</torque>
      <commandTopic>cmd_vel</commandTopic>
      <odometryTopic>odom</odometryTopic>
      <odometryFrame>odom</odometryFrame>
      <robotBaseFrame>robot_footprint</robotBaseFrame>
      <publishWheelTF>false</publishWheelTF>
      <publishWheelJointState>false</publishWheelJointState>
      <rosDebugLevel>na</rosDebugLevel>
      <wheelAcceleration>0</wheelAcceleration>
      <wheelTorque>5</wheelTorque>
      <odometrySource>world</odometrySource>
      <publishTf>1</publishTf>
      <publishOdomTF>true</publishOdomTF>
    </plugin>
  </gazebo>

libgazebo_ros_diff_drive.so is the shared object file created from compiling the C++ source code. The plugin accepts information specific to your robot's model, such as wheel separation, joint names, and more. Then it calculates and publishes the robot's odometry information to the topics that you specified, like odom . In an upcoming section, you will send velocity commands to your robot to move it in a specific direction. This controller helps achieve that result.

If you'd like to understand how this plugin was created, you can refer to its C++ source code .

Gazebo already has several such plugins publicly available. We will utilize the preexisting plugins for the camera sensor and the preexisting plugins for the Hokuyo lidar sensor. Both of these are already included in the my_robot.gazebo file linked previously.

ROS Communication

You need to define the topics to which each sensor publishes.

For the wheel joints, it's the cmd_vel topic.

<commandTopic>cmd_vel</commandTopic>

For the camera, it's the rgb/image_raw topic.

<imageTopicName>rgb/image_raw</imageTopicName>

And for the lidar, it's the scan topic

<topicName>/scan</topicName>

Import Plugins

Before we proceed to test these sensors and actuators with ROS, you need to make sure that your plugins are imported by your URDF my_robot.xacro file as well.
Import the sensors plugins by adding the following code to the top of the file (immediately before you define the robot_footprint link):

<xacro:include filename="$(find my_robot)/urdf/my_robot.gazebo" />

Next

Now, you’re ready to test these sensors with ROS!

Task Description:

Follow these steps to add the Gazebo sensor plugins to your robot:

Task List:

Task Feedback:

Great job!